clear
set more      off
set varabbrev off
set gr        off
set linesize 255

/* INPUTS */

local in_ui 		"/data2/cedsei/data2/search_ui"
local in_rams 		"/data2/cedsei/data2/monthly_ee_panel_rkd"
local in_sokat 		"/data2/cedsei/data2/sokatper_by_month_v2.dta" 	// Where is this produced? By Jonas C?

/* OUTPUTS */

local out_uirams 	"/data2/cedsei/data2/search_ui_rams_ww"

*cd "/data2/cedsei/data2"

********************************************************************************

clear 
use `in_ui'

count
rename date date_act
foreach num of numlist 0(1)6 {
	di "`num'"
	qui {
	gen date = date_act + `num'
	format date %tm
	merge 1:1 lopnr date using `in_rams', keep(1 3) nogen
	/*
	gen temp = year(dofm(date)) 
	tab temp _merge
	*/
	
	replace working = 0 		if mi(working)
	replace earnings_month = 0 	if mi(earnings_month)
	rename working working_`num'
	rename earnings_month earnings_month_`num'
	rename manl manl_`num' 
	rename private private_`num' 

	merge 1:1 lopnr date using "`in_sokat'", keep(1 3) nogen 
	gen pes_se_`num' = cond(!mi(fullsearch),1,0)
	gen fte_se_`num' = cond(!mi(fullsearch) & fullsearch==1,1,0)
	drop date fullsearch 
	}
}
rename date_act date 
count 

save `out_uirams', replace 
